<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Exercise 4.38(b): Linear matrix inequalities with one variable</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/cvxbook/Ch04_cvx_opt_probs/html/ex_4_38.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Exercise 4.38(b): Linear matrix inequalities with one variable</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% From Boyd &amp; Vandenberghe, "Convex Optimization"</span>
<span class="comment">% Jo&euml;lle Skaf - 09/26/05</span>
<span class="comment">%</span>
<span class="comment">% Finds the optimal t that would maximize c*t while still having A - t*B</span>
<span class="comment">% positive semidefinite by solving the following SDP:</span>
<span class="comment">%           minimize    c*t</span>
<span class="comment">%               s.t.    t*B &lt;= A</span>
<span class="comment">% c can either be a positive or negative real number</span>

<span class="comment">% Generate input data</span>
randn(<span class="string">'state'</span>,0);
n = 4;
A = randn(n); A = 0.5*(A'+A); <span class="comment">%A = A'*A;</span>
B = randn(n); B = B'*B;
<span class="comment">% can modify the value of c (&gt;0 or &lt;0)</span>
c = -1;

<span class="comment">% Create and solve the model</span>
cvx_begin <span class="string">sdp</span>
    variable <span class="string">t</span>
    minimize ( c*t )
    A &gt;= t * B;
cvx_end

<span class="comment">% Display results</span>
disp(<span class="string">'------------------------------------------------------------------------'</span>);
disp(<span class="string">'The optimal t obtained is'</span>);
disp(t);
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Calling sedumi: 10 variables, 9 equality constraints
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 9, order n = 5, dim = 17, blocks = 2
nnz(A) = 18 + 0, nnz(ADA) = 81, nnz(L) = 45
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            7.41E+00 0.000
  1 :   1.50E+00 1.38E+00 0.000 0.1864 0.9000 0.9000   0.26  1  1  1.9E+00
  2 :   6.02E+00 2.83E-01 0.000 0.2051 0.9000 0.9000  -0.08  1  1  1.1E+00
  3 :   4.20E+01 2.00E-02 0.000 0.0706 0.9900 0.9900  -0.62  1  1  5.4E-01
  4 :   6.03E+01 1.87E-03 0.000 0.0937 0.9900 0.9900  -0.13  1  1  1.0E-01
  5 :   4.85E+01 7.65E-05 0.444 0.0409 0.9900 0.9900   0.98  1  1  4.1E-03
  6 :   4.81E+01 4.33E-07 0.000 0.0057 0.9769 0.9900   0.99  1  1  9.4E-05
  7 :   4.81E+01 2.01E-08 0.214 0.0464 0.9900 0.9585   1.00  1  1  4.4E-06
  8 :   4.81E+01 6.35E-10 0.000 0.0316 0.9900 0.9900   1.00  2  2  1.4E-07
  9 :   4.81E+01 3.38E-11 0.065 0.0532 0.9900 0.9900   1.00  2  2  7.4E-09

iter seconds digits       c*x               b*y
  9      0.0   Inf  4.8119383092e+01  4.8119383403e+01
|Ax-b| =   1.5e-08, [Ay-c]_+ =   1.2E-09, |x|=  4.8e+02, |y|=  1.2e+02

Detailed timing (sec)
   Pre          IPM          Post
0.000E+00    5.000E-02    0.000E+00    
Max-norms: ||b||=2.368443e+00, ||c|| = 5.424573e-01,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 176.719.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +48.354
------------------------------------------------------------------------
The optimal t obtained is
  -48.3540

</pre>
</div>
</body>
</html>